package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.SwitchCabinetCreateReqDTO;
import com.huaxin.device.dto.request.SwitchCabinetPageListReqDTO;
import com.huaxin.device.dto.request.SwitchCabinetUpdateReqDTO;
import com.huaxin.device.models.SwitchCabinet;
import com.huaxin.device.service.SwitchCabinetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "变电箱/开关柜")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/switchCabinet")
public class SwitchCabinetController {

    private final SwitchCabinetService service;

    @Operation(summary = "创建变电箱", description = "创建变电箱")
    @PostMapping("/create")
    public ResponseResult<SwitchCabinet> create(@RequestBody @Valid SwitchCabinetCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取变电箱", description = "根据ID获取变电箱")
    @GetMapping("/get")
    public ResponseResult<SwitchCabinet> get(
            @Parameter(description = "变电箱ID", example = "sc123e456-789a-bcde-f012-3456789abcde")
            @RequestParam("id") String id) {
        return ResponseResult.ok(service.getByCabinetId(id));
    }

    @Operation(summary = "更新变电箱", description = "更新变电箱信息")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid SwitchCabinetUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除变电箱", description = "删除变电箱")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(
            @Parameter(description = "变电箱ID", example = "sc123e456-789a-bcde-f012-3456789abcde")
            @PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "分页查询变电箱", description = "分页查询变电箱")
    @PostMapping("/page")
    public ResponseResult<IPage<SwitchCabinet>> pageQuery(@RequestBody @Valid SwitchCabinetPageListReqDTO in) {
        return service.pageQuery(in);
    }

    @Operation(summary = "根据ID列表查询变电箱列表", description = "根据ID列表查询变电箱列表")
    @PostMapping("/list")
    public ResponseResult<List<SwitchCabinet>> listByIds(@RequestBody List<String> ids) {
        return service.listByIds(ids);
    }

    @Operation(summary = "根据组织ID查询变电箱列表", description = "根据组织ID查询变电箱列表")
    @GetMapping("/listByOrgId")
    public ResponseResult<List<SwitchCabinet>> listByOrgId(@Parameter(description = "组织ID", example = "org-01") @RequestParam(value = "orgId", required = true) String orgId) {
        return service.listByOrgId(orgId);
    }

    @Operation(summary = "根据组织ID列表查询变电箱列表", description = "根据组织ID列表查询变电箱列表")
    @PostMapping("/listByOrgIds")
    public ResponseResult<List<SwitchCabinet>> listByOrgIds(@RequestBody List<String> orgIds) {
        return service.listByOrgIds(orgIds);
    }

    @Operation(summary = "根据家庭ID查询变电箱列表", description = "根据家庭ID查询变电箱列表")
    @GetMapping("/listByFamilyId")
    public ResponseResult<List<SwitchCabinet>> listByFamilyId(@Parameter(description = "家庭ID", example = "family-01") @RequestParam(value = "familyId", required = true) String familyId) {
        return service.listByFamilyId(familyId);
    }

    @Operation(summary = "根据家庭ID列表查询变电箱列表", description = "根据家庭ID列表查询变电箱列表")
    @PostMapping("/listByFamilyIds")
    public ResponseResult<List<SwitchCabinet>> listByFamilyIds(@RequestBody List<String> familyIds) {
        return service.listByFamilyIds(familyIds);
    }

    @Operation(summary = "根据类型查询变电箱列表", description = "根据类型查询变电箱列表")
    @GetMapping("/listByType")
    public ResponseResult<List<SwitchCabinet>> listByType(@Parameter(description = "类型", example = "1") @RequestParam(value = "type", required = true) String type) {
        return service.listByType(type);
    }
}